package com.hanamaki.util.utiltest;

import java.sql.*;

/**
 * 链接数据库的步骤 ：jdbc
 * 1. 添加 依赖
 * 2. 注册驱动
 * 3. 编写数据库链接信息配置
 * 4. 开始连接
 *
 */
public class JdbcTest {

    public static void main(String[] args) throws Exception {

        Class.forName("com.mysql.cj.jdbc.Driver");
        String username = "root";
        String password = "123456";
        String url = "jdbc:mysql://127.0.0.1:3306/db?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
        /* connection 代表数据库对象 */
        Connection connection = DriverManager.getConnection(url, username, password);
        /* 如果链接成功 就要去实例化一个 编写sql并且可以执行sql 的对象 */
        Statement statement = connection.createStatement();
        String sql = "SELECT * from stu_info";
        ResultSet resultSet = statement.executeQuery(sql);
        while (resultSet.next()) {
            System.out.println(resultSet.getObject("stu_id"));
        }


    }
}

